package Run_System;

import java.util.*;

public class Exercises {
    private LinkedHashSet<Equation> exercises = new LinkedHashSet<Equation>();          //存放操作数的集合


    public int getSize() {          //返回集合元素个数
        return exercises.size();
    }



    public void generateAddExercises(int size){                                  //生成加法习题
        int i = 0;
        while( i < size){
            Equation equation = EquationFactory.generateAddEquation();
            if(!exercises.contains(equation)) {
                exercises.add(equation);
                i++;
            }
        }
    }

    public void generateSubstractExercises(int size){                              //生成减法习题
        int i = 0;
        while( i < size){
            Equation equation = EquationFactory.generateSubstractEquation();
            if(!exercises.contains(equation)){
                exercises.add(equation);
                i++;
            }
        }
    }

    protected void addEquation(Equation equation){ //添加算式
        if(equation != null)
            exercises.add(equation);
    }

    public Equation[] toArray(){
        return  exercises.toArray(new Equation[0]);
    }

    public  Iterator<Equation> iterator(){           //返回迭代器用来遍历集合
        return  exercises.iterator();
    }

     public String toString(){
        return  super.toString();
     }

    public static void main(String[] args) {
        Exercises exercises = new Exercises();
        exercises.generateSubstractExercises(100);
        System.out.println(exercises.getSize());
    }
}
